package cn.com.cetccst.sdk.openapi;

import android.content.Context;
import android.text.TextUtils;

import java.util.HashMap;
import java.util.Map;

import cn.com.cetccst.sdk.modelbase.ErrorMessage;
import cn.com.cetccst.sdk.utils.SSAPIUtil;

public class SSAPIFactory {

    public static final String TAG = SSAPIFactory.class.getSimpleName();
    private static Map<String, ISSAPI> issapiMap = new HashMap<>();

    public static ISSAPI getInstance(Context context, String appKey) {

        if(context != null) {
            SSAPIUtil.init(context.getApplicationContext());
            if (ErrorMessage.getMap() == null)
                ErrorMessage.init(context.getApplicationContext());
        }

        if (TextUtils.isEmpty(appKey)) {
            return null;
        }
        ISSAPI issapi = issapiMap.get(appKey);
        if (issapi != null) {
            return issapi;
        }
        issapi = new SSApiImpl(context, appKey);
        if (!TextUtils.isEmpty(appKey)) {
            issapiMap.put(appKey, issapi);
        }
        return issapi;
    }

    private SSAPIFactory() {
        throw new RuntimeException(this.getClass().getSimpleName() + " should not be instantiated");
    }

}
